'''
@Author: your name
@Date: 2020-06-05 14:11:28
@LastEditTime: 2020-06-05 14:18:52
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: /mtl-text-recognition/config/invoice_data_script.py
'''
# -*- encoding: utf-8 -*-
# author:lmolhw
# datetime:2020-4-14 9:47

"""
文件说明：crop发票图像、label

"""
import os

def open_txt(file_name):
    with open(file_name, 'r') as f:
        try:
            line = f.readline()
            while line:
                yield line.strip()
                line = f.readline()
        except:
            print('No value')


# file_path = '/data2/text_eval/detection/invoice_gen_v2/annotations'


# invoice_txt = open('./invoice.txt', 'w')
# for file in os.listdir(file_path):
#     file_name = os.path.join(file_path, file)

#     for line in open_txt(file_name):
#         boxes_tmp = line.split(',')
#         xmin, ymin, xmax, ymax, gt, id = int(float(boxes_tmp[0])), int(float(boxes_tmp[1])), int(
#                    float(boxes_tmp[4])), int(float(boxes_tmp[5])), str(boxes_tmp[8]), str(boxes_tmp[9])

#         box = (xmin, ymin, xmax, ymax)
#         # img_tmp = img.crop(box=box)
#         invoice_txt.writelines(gt.strip() + '\n')

# 处理全角字符
file_path = './invoice.txt'
chars = {'Ｗ', '８','Ｈ', '＃', 'Ｍ', 'Ｔ', 'Ｂ', '２','?', '１', '４','﹟', '０', '６', 'Ｃ','５','３','／','９','Ｖ'}
cre_chars = {'W', '8', 'H', '#'}
del_chars = {'〇','\ue5c5'}